package com.test.controller.admin;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.test.controller.Admininfo.ResData;
import com.test.entity.LeaveInfo;
import com.test.entity.NoticeInfo;
import com.test.service.LeaveInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * 请假(LeaveInfo)表控制层
 *
 * @author makejava
 * @since 2022-11-12 11:18:51
 */
@Controller
public class AdminLeaveInfoController {
    @Autowired
    private LeaveInfoService leaveInfoService;
    //    显示页面信息
    @GetMapping("admin/leave_info")
    public ModelAndView getLeaveInfo() {
        return new ModelAndView("admin/leave_info/list");
    }

    //    显示请假管理信息
    @GetMapping("admin/leave_info/queryList")
    @ResponseBody
    public String getQueryList(Integer page, LeaveInfo leaveInfo) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.writeValueAsString(leaveInfoService.queryByPage(leaveInfo, PageRequest.of(page - 1, 10)));
    }

    //    删除请假页面信息
    @GetMapping("admin/leave_info/del")
    @ResponseBody
    public ResData getDelete(Integer id) {
        ResData resData = new ResData();
        boolean b = leaveInfoService.deleteById(id);
        if (b) {
            resData.setCode(1);
            resData.setMsg("删除成功");
            return resData;
        }
        resData.setCode(0);
        resData.setMsg("删除失败");
        return resData;
    }


}

